package com.sandking.db.dao;

import javax.sql.DataSource;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.commons.dbutils.QueryRunner;
import com.sandking.config.SK_Config;
import java.sql.Connection;
import com.sandking.metadata.jdbc.SK_Query;
import java.util.Map;
import com.sandking.db.bean.Yhjz;
import java.util.List;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.handlers.MapListHandler;

public class YhjzDao {
	public static Yhjz insert(Yhjz yhjz){
		Connection conn = SK_Config.getConnection();
		return insert(yhjz,conn);
	}
	
	public static Yhjz insert(Yhjz yhjz,Connection conn){
		return insert(yhjz,conn,Yhjz.TABLENAME);
	}
	
	public static Yhjz insert(Yhjz yhjz,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return insert(yhjz,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Yhjz insert(Yhjz yhjz,String tableName){
		Connection conn = SK_Config.getConnection();
		return insert(yhjz,conn,tableName);
	}
	
	public static Yhjz insert(Yhjz yhjz,Connection conn,String tableName){
		
		SK_Query sq = new SK_Query();
		String sql = "INSERT INTO " +tableName+ " (id,tempid,建筑id,建筑lvl,x,y,用户_id,最后收取时间,最后升级时间,开始加速时间,结束加速时间,损坏) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			int i = (int)sq.insert(conn,sql,yhjz.getId(),yhjz.getTempid(),yhjz.getJzid(),yhjz.getJzlvl(),yhjz.getX(),yhjz.getY(),yhjz.getYh_id(),yhjz.getZhsqsj(),yhjz.getZhsjsj(),yhjz.getKsjssj(),yhjz.getJsjssj(),yhjz.getSh());
			if(yhjz.getId()==0){
				yhjz.setId(i);
			}
			return i > 0 ? yhjz : null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static Yhjz insert(Yhjz yhjz,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return insert(yhjz,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static int[] insertBatch(List<Yhjz> yhjzs){
		Connection conn = SK_Config.getConnection();
		return insertBatch(yhjzs,conn);
	}
	
	public static int[] insertBatch(List<Yhjz> yhjzs,Connection conn){
		return insertBatch(yhjzs,conn,Yhjz.TABLENAME);
	}
	
	public static int[] insertBatch(List<Yhjz> yhjzs,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return insertBatch(yhjzs,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static int[] insertBatch(List<Yhjz> yhjzs,String tableName){
		Connection conn = SK_Config.getConnection();
		return insertBatch(yhjzs,conn,tableName);
	}
	
	public static int[] insertBatch(List<Yhjz> yhjzs,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "INSERT INTO " +tableName+ " (id,tempid,建筑id,建筑lvl,x,y,用户_id,最后收取时间,最后升级时间,开始加速时间,结束加速时间,损坏) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			int columnSize = 12;
			int size = yhjzs.size();
			Object[][] params = new Object[size][columnSize];
			for (int i = 0; i < size; i++) {
				params[i][0] =yhjzs.get(i).getId();
				params[i][1] =yhjzs.get(i).getTempid();
				params[i][2] =yhjzs.get(i).getJzid();
				params[i][3] =yhjzs.get(i).getJzlvl();
				params[i][4] =yhjzs.get(i).getX();
				params[i][5] =yhjzs.get(i).getY();
				params[i][6] =yhjzs.get(i).getYh_id();
				params[i][7] =yhjzs.get(i).getZhsqsj();
				params[i][8] =yhjzs.get(i).getZhsjsj();
				params[i][9] =yhjzs.get(i).getKsjssj();
				params[i][10] =yhjzs.get(i).getJsjssj();
				params[i][11] =yhjzs.get(i).getSh();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 1 ? is : new int[]{};
		} catch (Exception e) {
			e.printStackTrace();
			return new int[]{};
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static int[] insertBatch(List<Yhjz> yhjzs,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return insertBatch(yhjzs,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static Yhjz update(Yhjz yhjz){
		Connection conn = SK_Config.getConnection();
		return update(yhjz,conn);
	}
	
	public static Yhjz update(Yhjz yhjz,Connection conn){
		return update(yhjz,conn,Yhjz.TABLENAME);
	}
	
	public static Yhjz update(Yhjz yhjz,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return update(yhjz,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Yhjz update(Yhjz yhjz,String tableName){
		Connection conn = SK_Config.getConnection();
		return update(yhjz,conn,tableName);
	}
	
	public static Yhjz update(Yhjz yhjz,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		StringBuffer sb = new StringBuffer();
		Map<String, Object> updateColumns = yhjz.getUpdateColumns();
		int columnSize = updateColumns.size();
		if (updateColumns.isEmpty()) {
			return yhjz;
		}
		sb.append("UPDATE ");
		sb.append(tableName);
		sb.append(" SET ");
		Object[] values = new Object[(columnSize + 1)];
		int i = 0;
		for (Map.Entry<String, Object> updateColumn : updateColumns.entrySet()) {
			String key = updateColumn.getKey();
			values[i] = updateColumn.getValue();
			i++;
			sb.append(key);
			sb.append("=");
			sb.append("?");
			if (i < columnSize) {
				sb.append(",");
			}
		}
		sb.append(" WHERE ");
		sb.append("id");
		sb.append(" = ?");
		values[columnSize] = yhjz.getId();
		String sql = sb.toString();
		try {
			i = run.update(conn, sql, values);			
			return i == 1 ? yhjz : null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}finally {
			try{
				yhjz.clearUpdateColumn();
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static Yhjz update(Yhjz yhjz,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return update(yhjz,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static int[] updateBatch(List<Yhjz> yhjzs){
		Connection conn = SK_Config.getConnection();
		return updateBatch(yhjzs,conn);
	}
	
	public static int[] updateBatch(List<Yhjz> yhjzs,Connection conn){
		return updateBatch(yhjzs,conn,Yhjz.TABLENAME);
	}
	
	public static int[] updateBatch(List<Yhjz> yhjzs,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return updateBatch(yhjzs,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static int[] updateBatch(List<Yhjz> yhjzs,String tableName){
		Connection conn = SK_Config.getConnection();
		return updateBatch(yhjzs,conn,tableName);
	}
	
	public static int[] updateBatch(List<Yhjz> yhjzs,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "UPDATE " +tableName+ " SET id = ?,tempid = ?,建筑id = ?,建筑lvl = ?,x = ?,y = ?,用户_id = ?,最后收取时间 = ?,最后升级时间 = ?,开始加速时间 = ?,结束加速时间 = ?,损坏 = ? WHERE id = ?";
		try {
			int columnSize = 12;
			int size = yhjzs.size();
			Object[][] params = new Object[size][columnSize + 1];
			for (int i = 0; i < size; i++) {
				params[i][0] =yhjzs.get(i).getId();
				params[i][1] =yhjzs.get(i).getTempid();
				params[i][2] =yhjzs.get(i).getJzid();
				params[i][3] =yhjzs.get(i).getJzlvl();
				params[i][4] =yhjzs.get(i).getX();
				params[i][5] =yhjzs.get(i).getY();
				params[i][6] =yhjzs.get(i).getYh_id();
				params[i][7] =yhjzs.get(i).getZhsqsj();
				params[i][8] =yhjzs.get(i).getZhsjsj();
				params[i][9] =yhjzs.get(i).getKsjssj();
				params[i][10] =yhjzs.get(i).getJsjssj();
				params[i][11] =yhjzs.get(i).getSh();
				params[i][columnSize] =yhjzs.get(i).getId();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 1 ? is : new int[]{};
		} catch (Exception e) {
			e.printStackTrace();
			return new int[]{};
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static int[] updateBatch(List<Yhjz> yhjzs,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return updateBatch(yhjzs,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static boolean delete(Yhjz yhjz){
		Connection conn = SK_Config.getConnection();
		return delete(yhjz,conn);
	}
	
	public static boolean delete(Yhjz yhjz,Connection conn){
		return delete(yhjz,conn,Yhjz.TABLENAME);
	}
	
	public static boolean delete(Yhjz yhjz,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return delete(yhjz,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean delete(Yhjz yhjz,String tableName){
		Connection conn = SK_Config.getConnection();
		return delete(yhjz,conn,tableName);
	}
	
	public static boolean delete(Yhjz yhjz,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "DELETE FROM " + tableName + " WHERE id = ?";
		try {
			int i = run.update(conn,sql, yhjz.getId());
			return i > 0 ? true : false;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return false;
			}
		}
	}
	
	public static boolean delete(Yhjz yhjz,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return delete(yhjz,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	
	public static boolean deleteBatch(List<Yhjz> yhjzs){
		Connection conn = SK_Config.getConnection();
		return deleteBatch(yhjzs,conn);
	}
	
	public static boolean deleteBatch(List<Yhjz> yhjzs,Connection conn){
		return deleteBatch(yhjzs,conn,Yhjz.TABLENAME);
	}
	
	public static boolean deleteBatch(List<Yhjz> yhjzs,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return deleteBatch(yhjzs,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean deleteBatch(List<Yhjz> yhjzs,String tableName){
		Connection conn = SK_Config.getConnection();
		return deleteBatch(yhjzs,conn,tableName);
	}
	
	public static boolean deleteBatch(List<Yhjz> yhjzs,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "DELETE FROM " + tableName + " WHERE id = ?";
		try {
			int size = yhjzs.size();
			Object[][] params = new Object[size][1];
			for (int i = 0; i < size; i++) {
				params[i][0] = yhjzs.get(i).getId();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 0;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return false;
			}
		}
	}
	
	public static boolean deleteBatch(List<Yhjz> yhjzs,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return deleteBatch(yhjzs,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * 根据( id ) 查询
	 */
	public static Yhjz getById(int id){
		Connection conn = SK_Config.getConnection();
		return getById(id, conn);
	}
	
	public static Yhjz getById(int id,String tableName){
		Connection conn = SK_Config.getConnection();
		return getById(id, conn,tableName);
	}
	
	/**
	 * 根据( tempid  用户_id ) 查询
	 */
	public static Yhjz getByTempidYh_id(int tempid, int yh_id){
		Connection conn = SK_Config.getConnection();
		return getByTempidYh_id(tempid, yh_id, conn);
	}
	
	public static Yhjz getByTempidYh_id(int tempid, int yh_id,String tableName){
		Connection conn = SK_Config.getConnection();
		return getByTempidYh_id(tempid, yh_id, conn,tableName);
	}
	
	/**
	 * 根据( 用户_id ) 查询
	 */
	public static List<Yhjz> getByYh_id(int yh_id){
		Connection conn = SK_Config.getConnection();
		return getByYh_id(yh_id, conn);
	}
	
	public static List<Yhjz> getByYh_id(int yh_id,String tableName){
		Connection conn = SK_Config.getConnection();
		return getByYh_id(yh_id, conn,tableName);
	}
	
	public static List<Yhjz> getByPageYh_id(int yh_id,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageYh_id(yh_id, conn,page,pageCount);
	}
	
	public static List<Yhjz> getByPageYh_id(int yh_id,String tableName,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageYh_id(yh_id, conn,tableName,page,pageCount);
	}
	/**
	 * 根据( 建筑id  用户_id ) 查询
	 */
	public static List<Yhjz> getByJzidYh_id(int jzid, int yh_id){
		Connection conn = SK_Config.getConnection();
		return getByJzidYh_id(jzid, yh_id, conn);
	}
	
	public static List<Yhjz> getByJzidYh_id(int jzid, int yh_id,String tableName){
		Connection conn = SK_Config.getConnection();
		return getByJzidYh_id(jzid, yh_id, conn,tableName);
	}
	
	public static List<Yhjz> getByPageJzidYh_id(int jzid, int yh_id,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageJzidYh_id(jzid, yh_id, conn,page,pageCount);
	}
	
	public static List<Yhjz> getByPageJzidYh_id(int jzid, int yh_id,String tableName,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageJzidYh_id(jzid, yh_id, conn,tableName,page,pageCount);
	}
	
	//Connection
	/**
	 * 根据( id ) 查询
	 */
	public static Yhjz getById(int id,Connection conn){
		return getById(id,conn,Yhjz.TABLENAME);
	}
	
	public static Yhjz getById(int id,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,tempid,建筑id,建筑lvl,x,y,用户_id,最后收取时间,最后升级时间,开始加速时间,结束加速时间,损坏 FROM " + tableName + " WHERE " + "id = ?";
		Yhjz yhjz = null; 
		try {
			Map<String, Object> map = run.query(conn,sql, new MapHandler(), id);
			yhjz = Yhjz.createForColumnNameMap(map);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhjz;
	}
	
	/**
	 * 根据( tempid  用户_id ) 查询
	 */
	public static Yhjz getByTempidYh_id(int tempid, int yh_id,Connection conn){
		return getByTempidYh_id(tempid, yh_id,conn,Yhjz.TABLENAME);
	}
	
	public static Yhjz getByTempidYh_id(int tempid, int yh_id,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,tempid,建筑id,建筑lvl,x,y,用户_id,最后收取时间,最后升级时间,开始加速时间,结束加速时间,损坏 FROM " + tableName + " WHERE " + "tempid = ? AND yh_id = ?";
		Yhjz yhjz = null; 
		try {
			Map<String, Object> map = run.query(conn,sql, new MapHandler(), tempid, yh_id);
			yhjz = Yhjz.createForColumnNameMap(map);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhjz;
	}
	
	/**
	 * 根据( 用户_id ) 查询
	 */
	public static List<Yhjz> getByYh_id(int yh_id,Connection conn){
		return getByYh_id(yh_id,conn,Yhjz.TABLENAME);
	}
	
	public static List<Yhjz> getByYh_id(int yh_id,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,tempid,建筑id,建筑lvl,x,y,用户_id,最后收取时间,最后升级时间,开始加速时间,结束加速时间,损坏 FROM " + tableName + " WHERE " + "yh_id = ?";
		List<Yhjz> yhjzs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), yh_id);
			yhjzs = Yhjz.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhjzs;
	}
	
	//-----------------------------------page-----------------------------------
	public static List<Yhjz> getByPageYh_id(int yh_id,Connection conn,int page,int pageCount){
		return getByPageYh_id(yh_id,conn,Yhjz.TABLENAME,page,pageCount);
	}
	
	public static List<Yhjz> getByPageYh_id(int yh_id,Connection conn,String tableName,int page,int pageCount){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageCount);
		String sql = "SELECT id,tempid,建筑id,建筑lvl,x,y,用户_id,最后收取时间,最后升级时间,开始加速时间,结束加速时间,损坏 FROM " + tableName + " WHERE " + "yh_id = ? LIMIT " + page + " , " +pageCount;
		List<Yhjz> yhjzs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), yh_id);
			yhjzs = Yhjz.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhjzs;
	}
	/**
	 * 根据( 建筑id  用户_id ) 查询
	 */
	public static List<Yhjz> getByJzidYh_id(int jzid, int yh_id,Connection conn){
		return getByJzidYh_id(jzid, yh_id,conn,Yhjz.TABLENAME);
	}
	
	public static List<Yhjz> getByJzidYh_id(int jzid, int yh_id,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,tempid,建筑id,建筑lvl,x,y,用户_id,最后收取时间,最后升级时间,开始加速时间,结束加速时间,损坏 FROM " + tableName + " WHERE " + "jzid = ? AND yh_id = ?";
		List<Yhjz> yhjzs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), jzid, yh_id);
			yhjzs = Yhjz.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhjzs;
	}
	
	//-----------------------------------page-----------------------------------
	public static List<Yhjz> getByPageJzidYh_id(int jzid, int yh_id,Connection conn,int page,int pageCount){
		return getByPageJzidYh_id(jzid, yh_id,conn,Yhjz.TABLENAME,page,pageCount);
	}
	
	public static List<Yhjz> getByPageJzidYh_id(int jzid, int yh_id,Connection conn,String tableName,int page,int pageCount){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageCount);
		String sql = "SELECT id,tempid,建筑id,建筑lvl,x,y,用户_id,最后收取时间,最后升级时间,开始加速时间,结束加速时间,损坏 FROM " + tableName + " WHERE " + "jzid = ? AND yh_id = ? LIMIT " + page + " , " +pageCount;
		List<Yhjz> yhjzs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), jzid, yh_id);
			yhjzs = Yhjz.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhjzs;
	}
	
	//DataSource
	/**
	 * 根据( id ) 查询
	 */
	public static Yhjz getById(int id,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getById(id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Yhjz getById(int id,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getById(id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 根据( tempid  用户_id ) 查询
	 */
	public static Yhjz getByTempidYh_id(int tempid, int yh_id,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getByTempidYh_id(tempid, yh_id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Yhjz getByTempidYh_id(int tempid, int yh_id,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getByTempidYh_id(tempid, yh_id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 根据( 用户_id ) 查询
	 */
	public static List<Yhjz> getByYh_id(int yh_id,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getByYh_id(yh_id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhjz> getByYh_id(int yh_id,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getByYh_id(yh_id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	//-----------------------------------page-----------------------------------
	public static List<Yhjz> getByPageYh_id(int yh_id,DataSource ds,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageYh_id(yh_id, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhjz> getByPageYh_id(int yh_id,DataSource ds,String tableName,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageYh_id(yh_id, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * 根据( 建筑id  用户_id ) 查询
	 */
	public static List<Yhjz> getByJzidYh_id(int jzid, int yh_id,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getByJzidYh_id(jzid, yh_id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhjz> getByJzidYh_id(int jzid, int yh_id,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getByJzidYh_id(jzid, yh_id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	//-----------------------------------page-----------------------------------
	public static List<Yhjz> getByPageJzidYh_id(int jzid, int yh_id,DataSource ds,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageJzidYh_id(jzid, yh_id, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhjz> getByPageJzidYh_id(int jzid, int yh_id,DataSource ds,String tableName,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageJzidYh_id(jzid, yh_id, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	public static List<Yhjz> getAll(){
		Connection conn = SK_Config.getConnection();
		return getAll(conn);
	}
	
	public static List<Yhjz> getAll(Connection conn){
		return getAll(conn,Yhjz.TABLENAME);
	}
	
	public static List<Yhjz> getAll(DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getAll(conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhjz> getAll(String tableName){
		Connection conn = SK_Config.getConnection();
		return getAll(conn,tableName);
	}
	
	public static List<Yhjz> getAll(Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,tempid,建筑id,建筑lvl,x,y,用户_id,最后收取时间,最后升级时间,开始加速时间,结束加速时间,损坏 FROM " + tableName;
		List<Yhjz> yhjzs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler());
			yhjzs = Yhjz.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhjzs;
	}
	
	public static List<Yhjz> getAll(DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getAll(conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static List<Yhjz> getAllPage(int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getAllPage(conn,page,pageCount);
	}
	
	public static List<Yhjz> getAllPage(Connection conn,int page,int pageCount){
		return getAllPage(conn,Yhjz.TABLENAME,page,pageCount);
	}
	
	public static List<Yhjz> getAllPage(DataSource ds,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getAllPage(conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Yhjz> getAllPage(String tableName,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getAllPage(conn,tableName,page,pageCount);
	}
	
	public static List<Yhjz> getAllPage(Connection conn,String tableName,int page,int pageCount){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageCount);
		String sql = "SELECT id,tempid,建筑id,建筑lvl,x,y,用户_id,最后收取时间,最后升级时间,开始加速时间,结束加速时间,损坏 FROM " + tableName + " LIMIT " + page + " , " +pageCount;
		List<Yhjz> yhjzs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler());
			yhjzs = Yhjz.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return yhjzs;
	}
	
	public static List<Yhjz> getAllPage(DataSource ds,String tableName,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getAllPage(conn,tableName,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
}